<?php
/**
* 会员模型
*/
class Member_model extends MY_Model
{
	function __construct()
	{
		parent::__construct();
	}

	/**
	 * [获取会员列表]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @param    [type]     $page [页码]
	 * @param    [type]     $get  [筛选条件]
	 */
	function memberList($page, $get)
	{
		$where = array('del_status' => '0');
		$like = array();

		// 筛选用户姓名
		if (isset($get['name']) && !empty($get['name'])) {
			$like['name'] = $get['name'];
		}

		// 筛选注册起始时间
		if (isset($get['start_time']) && !empty($get['start_time'])) {
			$where['create_time >'] = $get['start_time'];
		}
		
		// 筛选注册截止时间
		if (isset($get['end_time']) && !empty($get['end_time'])) {
			$where['create_time <'] = $get['end_time'];
		}

		// 筛选角色
		if (isset($get['role']) && $get['role'] != 0) {
			$where['role'] = $get['role'];
		}

		$list = $this->hw_list('member', $where, '*', $like, $page);
		$count = $this->hw_countTable('member', $where, $like);

		if ($list) {
			$return = array(
				'code'  => 1,
				'msg'   => '数据获取成功',
				'list'  => $list,
				'count' => $count,
				);
		} else {
			$return = array(
				'code'  => 0,
				'msg'   => '暂无数据',
				'list'  => array(),
				'count' => $count,
				);
		}

		return $return;
	}

	/**
	 * [获取会员详情]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @param    [type]     $id [会员id]
	 */
	function memberDetail($id)
	{
		$where = array('id' => $id);

		$find = $this->hw_getRecord('member', $where, '*');

		if ($find) {
			$return = array(
				'code' => 1,
				'msg' => '数据获取成功',
				'find' => $find,
			);
		} else {
			$return = array(
				'code' => 0,
				'msg' => '数据获取失败',
			);
		}

		return $return;
	}

	/**
	 * [标记会员是否为海宝]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @param    [type]     $id   [会员id]
	 * @param    [type]     $type [0否1是]
	 * @return   [type]           [description]
	 */
	function signType($id, $type)
	{
		$where = array('id' => $id);
		$data = array(
			'type' => $type,
			'update_time' => date('Y-m-d H:i:s'),
		);

		$res = $this->hw_Update('member', $data, $where);

		if ($res) {
			$return = array(
				'code' => 1,
				'msg' => '操作成功',
			);
		} else {
			$return = array(
				'code' => 0,
				'msg' => '操作失败',
			);
		}

		return $return;
	}

	/**
	 * [ajax获取新会员数量]
	 * @Author   zt
	 * @DateTime 2018-08-22
	 * @return   [type]     [description]
	 */
	function ajaxGetNewMember()
	{
		$where = array(
			'del_status' => '0',
			'new_type' => '0',
		);

		$count = $this->hw_countTable('member', $where, array());

		if ($count) {
			$return = array(
				'code' => 1,
				'msg' => '新增用户数量获取成功',
				'member_num' => $count,
			);
		} else {
			$return = array(
				'code' => 0,
				'msg' => '无新增用户',
				'member_num' => 0,
			);
		}

		return $return;
	}

	/**
	 * [ajax修改新会员标记]
	 * @Author   zt
	 * @DateTime 2018-08-22
	 * @return   [type]     [description]
	 */
	function ajaxEditNewMember()
	{
		$where = array(
			'del_status' => '0',
			'new_type' => '0',
		);

		$data = array('new_type' => '1', 'update_time' => date('Y-m-d H:i:s'));

		$res = $this->hw_Update('member', $data, $where);

		if ($res) {
			$return = array(
				'code' => 1,
				'msg' => '修改成功',
			);
		} else {
			$return = array(
				'code' => 0,
				'msg' => '无可修改用户',
			);
		}

		return $return;
	}
}